
const util = require('../../utils/util.js');
Page({
  data: {
    // idCardImg: ['http://124.220.3.30:9000/miniapp-xjy-dev/public/fenlei/youerzhaohu.png', 'http://124.220.3.30:9000/miniapp-xjy-dev/public/fenlei/youerzhaohu.png'],
    idCardImg0: '',
    idCardImg1: '',
    idCard: '',
    name: '',
    mobile: '',
  },
  doUpLoadImage(e) {
    const _this = this;
    const data = e.currentTarget.dataset
    console.log(data)
    wx.chooseImage({
      count: 1,
      success(res) {
        console.log(res)
        wx.getFileSystemManager().readFile({
          filePath: res.tempFilePaths[0],
          encoding: "base64",
          success(res2) {
            console.log(res2)
            const sss = res2.data
            wx.showLoading({
              title: '文件上传中...',
            })
            util.https('comm/imageUpload', { imageBase64: sss }, (res) => {
              console.log(res)
              _this.setData({
                idCardImg1: res.imageUrl
              })
              wx.showToast({
                title: '上传成功',
                icon: 'success',
                duration: 5000
              })
            }, (res) => {
              console.log(res)
              wx.showModal({
                title: '温馨提示',
                content: '上传失败',
                confirmColor: '#F08302',
                showCancel: false,
                success(res) {
                }
              })
            }, () => {
              wx.hideLoading()
            })
          }
        })
      }
    })
  },
  doUpLoadImage1(e) {
    const _this = this;
    const data = e.currentTarget.dataset
    console.log(data)
    wx.chooseImage({
      count: 1,
      success(res) {
        console.log(res)
        wx.getFileSystemManager().readFile({
          filePath: res.tempFilePaths[0],
          encoding: "base64",
          success(res2) {
            console.log(res2)
            const sss = res2.data
            wx.showLoading({
              title: '文件上传中...',
            })
            util.https('comm/idCardOcr', { idCardImgFront: sss }, (res) => {
              console.log(res)
              _this.setData({
                idCardImg0: "data:image/jpeg;base64," + sss,
                name: res.name,
                idCard: res.idCardNo
              })
              wx.showToast({
                title: '上传成功',
                icon: 'success',
                duration: 5000
              })
            }, (res) => {
              console.log(res)
              wx.showModal({
                title: '温馨提示',
                content: '上传失败',
                confirmColor: '#F08302',
                showCancel: false,
                success(res) {
                }
              })
            }, () => {
              wx.hideLoading()
            }, false, true)
          }
        })
      }
    })
  },

  doNext() {
    let data = this.data;
    if (!data.idCardImg0) {
      wx.showModal({
        title: '温馨提示',
        content: '请上传身份证图片！',
        confirmColor: '#F08302',
        showCancel: false,
        success(res) {
        }
      })
      return
    }
    // if (!/^[1-9]\d{5}\d{2}((0[1-9])|(1[0-2]))\d{3}[0-9]$/.test(data.idCard)) {
    //   wx.showModal({
    //     title: '温馨提示',
    //     content: '身份证号码不正确！',
    //     confirmColor: '#F08302',
    //     showCancel: false,
    //     success(res) {
    //     }
    //   })
    //   return
    // }
    if (!data.name || data.name == null) {
      wx.showModal({
        title: '温馨提示',
        content: '姓名不能为空！',
        confirmColor: '#F08302',
        showCancel: false,
        success(res) {
        }
      })
      return
    }
    if (!/^1[3456789]\d{9}$/.test(data.mobile)) {
      wx.showModal({
        title: '温馨提示',
        content: '手机号码不正确！',
        confirmColor: '#F08302',
        showCancel: false,
        success(res) {
        }
      })
      return
    }
    try {
      let storageData = wx.getStorageSync('bmhetong');
      // storageData.idCardImg = [data.idCardImg0, data.idCardImg1].join();
      storageData.idCardImg = '';
      storageData.idCard = data.idCard;
      storageData.name = data.name;
      storageData.mobile = data.mobile;
      wx.setStorageSync('bmhetong', storageData);
      wx.navigateTo({ url: '/page5/bmhetongphoto/index' });
    } catch (e) { }

  },
  doBack() {
    wx.navigateBack({
      delta: 1
    })
  },


  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {
    console.log('onPullDownRefresh')
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
    console.log('onReachBottom')
  }
  
})